/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * ContraseNaUI.java
 *
 * Created on 19/06/2009, 09:22:54 PM
 */

package CRM_UI;

import DAO.DAOLogin;
import java.awt.Cursor;
import javax.swing.JFrame;
import javax.swing.JOptionPane;

/**
 *
 * @author L¡z
 */
public class ContraseNaUI extends javax.swing.JFrame {

    /** Creates new form ContraseNaUI */
    String login;
    JFrame objCoordinadorSC_UI;
    RSC_UI objRSC_UI;
    JefeVentasUI objJV;

    Cursor handCursor = new Cursor(Cursor.HAND_CURSOR);
    Cursor defaultCursor = new Cursor(Cursor.DEFAULT_CURSOR);

    public ContraseNaUI(String login, JFrame objCoordSc_UI)
    {
        this.objRSC_UI = objRSC_UI;
        this.login = login;
        initComponents();
        setLocationRelativeTo(null);

    }

     public ContraseNaUI(String login, CoordinadorServicioClienteUI objCoordSc_UI)
    {
        this.objCoordinadorSC_UI = objCoordSc_UI;
        this.login = login;
        initComponents();
        setLocationRelativeTo(null);

    }

      public ContraseNaUI(String login, JefeVentasUI objJV)
    {
        this.objJV = objJV;
        this.login = login;
        initComponents();
        setLocationRelativeTo(null);

    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        oldPassLabel = new javax.swing.JLabel();
        newPassLabel = new javax.swing.JLabel();
        confirmPassLabel = new javax.swing.JLabel();
        oldPasswordField = new javax.swing.JPasswordField();
        newPasswordField = new javax.swing.JPasswordField();
        confirmPasswordField = new javax.swing.JPasswordField();
        limpiarButton = new javax.swing.JButton();
        cambiarButton = new javax.swing.JButton();
        casitaBoton = new javax.swing.JLabel();

        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder("Contraseña"));

        oldPassLabel.setText("Contraseña antigua:");

        newPassLabel.setText("Contraseña nueva:");

        confirmPassLabel.setText("Confirmar contraseña:");

        limpiarButton.setText("Limpiar");
        limpiarButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                limpiarButtonActionPerformed(evt);
            }
        });

        cambiarButton.setText("Cambiar");
        cambiarButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cambiarButtonActionPerformed(evt);
            }
        });

        casitaBoton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/resources/home.png"))); // NOI18N
        casitaBoton.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                casitaBotonMouseClicked(evt);
            }
            public void mouseEntered(java.awt.event.MouseEvent evt) {
                casitaBotonMouseEntered(evt);
            }
            public void mouseExited(java.awt.event.MouseEvent evt) {
                casitaBotonMouseExited(evt);
            }
        });

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(confirmPassLabel)
                            .addComponent(oldPassLabel)
                            .addComponent(newPassLabel))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(newPasswordField, javax.swing.GroupLayout.DEFAULT_SIZE, 136, Short.MAX_VALUE)
                            .addComponent(oldPasswordField, javax.swing.GroupLayout.DEFAULT_SIZE, 136, Short.MAX_VALUE)
                            .addComponent(confirmPasswordField, javax.swing.GroupLayout.DEFAULT_SIZE, 136, Short.MAX_VALUE))
                        .addGap(29, 29, 29))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                        .addComponent(cambiarButton)
                        .addGap(18, 18, 18)
                        .addComponent(limpiarButton)
                        .addGap(18, 18, 18)
                        .addComponent(casitaBoton)
                        .addContainerGap())))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(oldPassLabel)
                    .addComponent(oldPasswordField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(newPassLabel)
                    .addComponent(newPasswordField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(confirmPassLabel)
                    .addComponent(confirmPasswordField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(limpiarButton, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(cambiarButton)
                    .addComponent(casitaBoton)))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, 166, Short.MAX_VALUE)
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void limpiarButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_limpiarButtonActionPerformed
        // TODO add your handling code here:
        oldPasswordField.setText("");
        newPasswordField.setText("");
        confirmPasswordField.setText("");
    }//GEN-LAST:event_limpiarButtonActionPerformed

    private void cambiarButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cambiarButtonActionPerformed
        // TODO add your handling code here:
        String oldPassword = new String (oldPasswordField.getPassword());
        String newPassword = new String (newPasswordField.getPassword());
        String confirmPassword = new String (confirmPasswordField.getPassword());
                
        if( newPassword.equals(confirmPassword))
        {
            DAOLogin objDaoLogin = new DAOLogin();
            int perfil = objDaoLogin.validarUsuario(login, oldPassword);

            if(perfil != -1)
            {
                objDaoLogin.actualizarContraseNa(login, newPassword);
                JOptionPane.showMessageDialog(null, "Contraseña actualizada exitosamente", "Contraseña Actualizada", JOptionPane.INFORMATION_MESSAGE);
            }
            else
            {
                JOptionPane.showMessageDialog(null, "Error en la contraseña actual.\nPor favor verfique la actual contraseña", "Contraseña No Actualizada", JOptionPane.ERROR_MESSAGE);
            }
        }
        else
        {
            JOptionPane.showMessageDialog(null, "Error al confirmar la nueva contraseña.\nPor favor verfique la nueva contraseña", "Contraseña No Actualizada", JOptionPane.ERROR_MESSAGE);
        }
    }//GEN-LAST:event_cambiarButtonActionPerformed

    private void casitaBotonMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_casitaBotonMouseClicked
        objCoordinadorSC_UI.setVisible(true);
        this.setVisible(false);
    }//GEN-LAST:event_casitaBotonMouseClicked

    private void casitaBotonMouseEntered(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_casitaBotonMouseEntered
        this.setCursor(handCursor);
    }//GEN-LAST:event_casitaBotonMouseEntered

    private void casitaBotonMouseExited(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_casitaBotonMouseExited
        this.setCursor(defaultCursor);
    }//GEN-LAST:event_casitaBotonMouseExited

    /**
    * @param args the command line arguments
    */

    /*
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new ContraseNaUI().setVisible(true);
            }
        });
    }
     * */

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton cambiarButton;
    private javax.swing.JLabel casitaBoton;
    private javax.swing.JLabel confirmPassLabel;
    private javax.swing.JPasswordField confirmPasswordField;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JButton limpiarButton;
    private javax.swing.JLabel newPassLabel;
    private javax.swing.JPasswordField newPasswordField;
    private javax.swing.JLabel oldPassLabel;
    private javax.swing.JPasswordField oldPasswordField;
    // End of variables declaration//GEN-END:variables

}
